package com.zj.easytotwitter.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.TextView;


import com.zj.easytotwitter.R;
import com.zj.easytotwitter.event.DataEvent;

import org.greenrobot.eventbus.EventBus;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by ZJ on 2017/7/31 0031.
 */

public class PolicyItemAdapter extends RecyclerView.Adapter<PolicyItemAdapter.MyViewHolder>{
    private LayoutInflater inflater;
    private List<String> infomationCatalogs;
    private OnItemClickLitener mOnItemClickLitener;

    public PolicyItemAdapter(Context context) {
        infomationCatalogs = new ArrayList<String>();
        inflater = LayoutInflater.from(context);
    }

    public PolicyItemAdapter(Context context,List<String> infomationCatalogs) {
        this.infomationCatalogs=infomationCatalogs;
        inflater = LayoutInflater.from(context);
    }

    @Override
    public MyViewHolder onCreateViewHolder(ViewGroup viewGroup, int i) {
        //PolicyItemAdapter.MyViewHolder holder = new PolicyItemAdapter.MyViewHolder(inflater.inflate(R.layout.item_policy_total,null));
        PolicyItemAdapter.MyViewHolder holder = new PolicyItemAdapter.MyViewHolder(inflater.inflate(R.layout.item_home_page_content,null));
        return holder;
    }

    @Override
    public void onBindViewHolder(final MyViewHolder holder, int i) {
        //holder.tvPolicyTitle.setText("你好呀");
        //holder.tvPolicyTime.setText("12:00");
        holder.btnShare.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                EventBus.getDefault().post(new DataEvent(9999,"分享图片"));
            }
        });
        if (mOnItemClickLitener != null){
            holder.itemView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    int pos = holder.getLayoutPosition();
                    mOnItemClickLitener.onItemClick(holder.itemView, pos);
                }
            });
        }
    }

    public void refreshItemAll(List<String> infomationCatalogs){
        this.infomationCatalogs = infomationCatalogs;
    }

    @Override
    public int getItemCount() {
        return infomationCatalogs.size();
    }

    public void setOnItemClickLitener(PolicyItemAdapter.OnItemClickLitener mOnItemClickLitener) {
        this.mOnItemClickLitener = mOnItemClickLitener;
    }

    public interface OnItemClickLitener {
        void onItemClick(View view, int position);
    }

   public class MyViewHolder extends RecyclerView.ViewHolder {

        TextView tvPolicyTitle;
        TextView tvPolicyTime;
        Button btnShare;

        public MyViewHolder(View view) {
            super(view);
            btnShare= (Button) view.findViewById(R.id.bt_share);
            //tvPolicyTitle = (TextView) view.findViewById(R.id.tv_policy_title);
            //tvPolicyTime = (TextView) view.findViewById(R.id.tv_policy_time);
        }
    }

}
